/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package myvalidators;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author lab1
 */
public class EmailValidator implements Validator {

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        String email = (String) value;
        Pattern pattem = Pattern.compile(".+@.+\\.[a-z]+");
        Matcher m = pattem.matcher(email);
        boolean mat = m.matches();
        if (!mat) {
            FacesMessage message = new FacesMessage();
            message.setSummary("Invalid Email !!!");
            throw new ValidatorException(message);
        }
    }
}
